use crate::src::test::alloc_testing::{alloc_test_set_limit, alloc_test_free};
use crate::src::src::slist::{slist_data, slist_find_data, slist_nth_data, slist_remove_entry, slist_next, slist_append, slist_iter_remove, slist_iter_has_more, slist_free, slist_iter_next, slist_nth_entry, slist_prepend, slist_sort, slist_to_array, slist_remove_data, slist_iterate, slist_length};
use crate::src::src::compare_int::{int_compare, int_equal};
use crate::src::test::framework::{run_tests};
use crate::src::struct_and_type::{_SListIterator, SListValue, SListIterator, _SListEntry, SListEqualFunc, UnitTestFunction, SListEntry, SListCompareFunc};
use ::libc;
extern "C" {
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
#[no_mangle]
pub static mut variable1_test_slist: i32 = 50 as i32;
#[no_mangle]
pub static mut variable2_test_slist: i32 = 0;
#[no_mangle]
pub static mut variable3_test_slist: i32 = 0;
#[no_mangle]
pub static mut variable4_test_slist: i32 = 0;
#[no_mangle]
pub unsafe extern "C" fn generate_list_test_slist() -> *mut SListEntry {
    let mut list: *mut SListEntry = 0 as *mut SListEntry;
    assert!(!(slist_append(&mut list, &mut variable1_test_slist as *mut i32 as SListValue))
        .is_null());
    assert!(!(slist_append(&mut list, &mut variable2_test_slist as *mut i32 as SListValue))
        .is_null());
    assert!(!(slist_append(&mut list, &mut variable3_test_slist as *mut i32 as SListValue))
        .is_null());
    assert!(!(slist_append(&mut list, &mut variable4_test_slist as *mut i32 as SListValue))
        .is_null());
    return list;
}
#[no_mangle]
pub unsafe extern "C" fn test_slist_append() {
    let mut list: *mut SListEntry = 0 as *mut SListEntry;
    assert!(!(slist_append(&mut list, &mut variable1_test_slist as *mut i32 as SListValue))
        .is_null());
    assert!(!(slist_append(&mut list, &mut variable2_test_slist as *mut i32 as SListValue))
        .is_null());
    assert!(!(slist_append(&mut list, &mut variable3_test_slist as *mut i32 as SListValue))
        .is_null());
    assert!(!(slist_append(&mut list, &mut variable4_test_slist as *mut i32 as SListValue))
        .is_null());
    assert!(slist_length(list) == 4 as i32 as u32);
    assert!(slist_nth_data(list, 0 as i32 as u32)
        == &mut variable1_test_slist as *mut i32 as SListValue);
    assert!(slist_nth_data(list, 1 as i32 as u32)
        == &mut variable2_test_slist as *mut i32 as SListValue);
    assert!(slist_nth_data(list, 2 as i32 as u32)
        == &mut variable3_test_slist as *mut i32 as SListValue);
    assert!(slist_nth_data(list, 3 as i32 as u32)
        == &mut variable4_test_slist as *mut i32 as SListValue);
    alloc_test_set_limit(0 as i32);
    assert!(slist_length(list) == 4 as i32 as u32);
    assert!((slist_append(&mut list, &mut variable1_test_slist as *mut i32 as SListValue))
        .is_null());
    assert!(slist_length(list) == 4 as i32 as u32);
    slist_free(list);
}
#[no_mangle]
pub unsafe extern "C" fn test_slist_prepend() {
    let mut list: *mut SListEntry = 0 as *mut SListEntry;
    assert!(!(slist_prepend(&mut list, &mut variable1_test_slist as *mut i32 as SListValue))
        .is_null());
    assert!(!(slist_prepend(&mut list, &mut variable2_test_slist as *mut i32 as SListValue))
        .is_null());
    assert!(!(slist_prepend(&mut list, &mut variable3_test_slist as *mut i32 as SListValue))
        .is_null());
    assert!(!(slist_prepend(&mut list, &mut variable4_test_slist as *mut i32 as SListValue))
        .is_null());
    assert!(slist_nth_data(list, 0 as i32 as u32)
        == &mut variable4_test_slist as *mut i32 as SListValue);
    assert!(slist_nth_data(list, 1 as i32 as u32)
        == &mut variable3_test_slist as *mut i32 as SListValue);
    assert!(slist_nth_data(list, 2 as i32 as u32)
        == &mut variable2_test_slist as *mut i32 as SListValue);
    assert!(slist_nth_data(list, 3 as i32 as u32)
        == &mut variable1_test_slist as *mut i32 as SListValue);
    alloc_test_set_limit(0 as i32);
    assert!(slist_length(list) == 4 as i32 as u32);
    assert!((slist_prepend(&mut list, &mut variable1_test_slist as *mut i32 as SListValue))
        .is_null());
    assert!(slist_length(list) == 4 as i32 as u32);
    slist_free(list);
}
#[no_mangle]
pub unsafe extern "C" fn test_slist_free() {
    let mut list: *mut SListEntry = 0 as *mut SListEntry;
    list = generate_list_test_slist();
    slist_free(list);
    slist_free(0 as *mut SListEntry);
}
#[no_mangle]
pub unsafe extern "C" fn test_slist_next() {
    let mut list: *mut SListEntry = 0 as *mut SListEntry;
    let mut rover: *mut SListEntry = 0 as *mut SListEntry;
    list = generate_list_test_slist();
    rover = list;
    assert!(slist_data(rover) == &mut variable1_test_slist as *mut i32 as SListValue);
    rover = slist_next(rover);
    assert!(slist_data(rover) == &mut variable2_test_slist as *mut i32 as SListValue);
    rover = slist_next(rover);
    assert!(slist_data(rover) == &mut variable3_test_slist as *mut i32 as SListValue);
    rover = slist_next(rover);
    assert!(slist_data(rover) == &mut variable4_test_slist as *mut i32 as SListValue);
    rover = slist_next(rover);
    assert!(rover.is_null());
    slist_free(list);
}
#[no_mangle]
pub unsafe extern "C" fn test_slist_nth_entry() {
    let mut list: *mut SListEntry = 0 as *mut SListEntry;
    let mut entry: *mut SListEntry = 0 as *mut SListEntry;
    list = generate_list_test_slist();
    entry = slist_nth_entry(list, 0 as i32 as u32);
    assert!(slist_data(entry) == &mut variable1_test_slist as *mut i32 as SListValue);
    entry = slist_nth_entry(list, 1 as i32 as u32);
    assert!(slist_data(entry) == &mut variable2_test_slist as *mut i32 as SListValue);
    entry = slist_nth_entry(list, 2 as i32 as u32);
    assert!(slist_data(entry) == &mut variable3_test_slist as *mut i32 as SListValue);
    entry = slist_nth_entry(list, 3 as i32 as u32);
    assert!(slist_data(entry) == &mut variable4_test_slist as *mut i32 as SListValue);
    entry = slist_nth_entry(list, 4 as i32 as u32);
    assert!(entry.is_null());
    entry = slist_nth_entry(list, 400 as i32 as u32);
    assert!(entry.is_null());
    slist_free(list);
}
#[no_mangle]
pub unsafe extern "C" fn test_slist_nth_data() {
    let mut list: *mut SListEntry = 0 as *mut SListEntry;
    list = generate_list_test_slist();
    assert!(slist_nth_data(list, 0 as i32 as u32)
        == &mut variable1_test_slist as *mut i32 as SListValue);
    assert!(slist_nth_data(list, 1 as i32 as u32)
        == &mut variable2_test_slist as *mut i32 as SListValue);
    assert!(slist_nth_data(list, 2 as i32 as u32)
        == &mut variable3_test_slist as *mut i32 as SListValue);
    assert!(slist_nth_data(list, 3 as i32 as u32)
        == &mut variable4_test_slist as *mut i32 as SListValue);
    assert!((slist_nth_data(list, 4 as i32 as u32)).is_null());
    assert!((slist_nth_data(list, 400 as i32 as u32)).is_null());
    slist_free(list);
}
#[no_mangle]
pub unsafe extern "C" fn test_slist_length() {
    let mut list: *mut SListEntry = 0 as *mut SListEntry;
    list = generate_list_test_slist();
    assert!(slist_length(list) == 4 as i32 as u32);
    slist_prepend(&mut list, &mut variable1_test_slist as *mut i32 as SListValue);
    assert!(slist_length(list) == 5 as i32 as u32);
    assert!(slist_length(0 as *mut SListEntry) == 0 as i32 as u32);
    slist_free(list);
}
#[no_mangle]
pub unsafe extern "C" fn test_slist_remove_entry() {
    let mut empty_list: *mut SListEntry = 0 as *mut SListEntry;
    let mut list: *mut SListEntry = 0 as *mut SListEntry;
    let mut entry: *mut SListEntry = 0 as *mut SListEntry;
    list = generate_list_test_slist();
    entry = slist_nth_entry(list, 2 as i32 as u32);
    assert!(slist_remove_entry(&mut list, entry) != 0 as i32);
    assert!(slist_length(list) == 3 as i32 as u32);
    entry = slist_nth_entry(list, 0 as i32 as u32);
    assert!(slist_remove_entry(&mut list, entry) != 0 as i32);
    assert!(slist_length(list) == 2 as i32 as u32);
    assert!(slist_remove_entry(&mut list, entry) == 0 as i32);
    assert!(slist_remove_entry(&mut list, 0 as *mut SListEntry) == 0 as i32);
    assert!(slist_remove_entry(&mut empty_list, 0 as *mut SListEntry) == 0 as i32);
    slist_free(list);
}
#[no_mangle]
pub unsafe extern "C" fn test_slist_remove_data() {
    let mut entries: [i32; 13] = [
        89 as i32,
        4 as i32,
        23 as i32,
        42 as i32,
        4 as i32,
        16 as i32,
        15 as i32,
        4 as i32,
        8 as i32,
        99 as i32,
        50 as i32,
        30 as i32,
        4 as i32,
    ];
    let mut num_entries: u32 = (::core::mem::size_of::<[i32; 13]>()
        as u64)
        .wrapping_div(::core::mem::size_of::<i32>() as u64)
        as u32;
    let mut val: i32 = 0;
    let mut list: *mut SListEntry = 0 as *mut SListEntry;
    let mut i: u32 = 0;
    list = 0 as *mut SListEntry;
    i = 0 as i32 as u32;
    while i < num_entries {
        slist_prepend(
            &mut list,
            &mut *entries.as_mut_ptr().offset(i as isize) as *mut i32
                as SListValue,
        );
        i = i.wrapping_add(1);
        i;
    }
    val = 0 as i32;
    assert!(slist_remove_data(
        &mut list,
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> i32,
        ),
        &mut val as *mut i32 as SListValue,
    ) == 0 as i32 as u32);
    val = 56 as i32;
    assert!(slist_remove_data(
        &mut list,
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> i32,
        ),
        &mut val as *mut i32 as SListValue,
    ) == 0 as i32 as u32);
    val = 8 as i32;
    assert!(slist_remove_data(
        &mut list,
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> i32,
        ),
        &mut val as *mut i32 as SListValue,
    ) == 1 as i32 as u32);
    assert!(slist_length(list) == num_entries.wrapping_sub(1 as i32 as u32));
    val = 4 as i32;
    assert!(slist_remove_data(
        &mut list,
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> i32,
        ),
        &mut val as *mut i32 as SListValue,
    ) == 4 as i32 as u32);
    assert!(slist_length(list) == num_entries.wrapping_sub(5 as i32 as u32));
    val = 89 as i32;
    assert!(slist_remove_data(
        &mut list,
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> i32,
        ),
        &mut val as *mut i32 as SListValue,
    ) == 1 as i32 as u32);
    assert!(slist_length(list) == num_entries.wrapping_sub(6 as i32 as u32));
    slist_free(list);
}
#[no_mangle]
pub unsafe extern "C" fn test_slist_sort() {
    let mut list: *mut SListEntry = 0 as *mut SListEntry;
    let mut entries: [i32; 13] = [
        89 as i32,
        4 as i32,
        23 as i32,
        42 as i32,
        4 as i32,
        16 as i32,
        15 as i32,
        4 as i32,
        8 as i32,
        99 as i32,
        50 as i32,
        30 as i32,
        4 as i32,
    ];
    let mut sorted: [i32; 13] = [
        4 as i32,
        4 as i32,
        4 as i32,
        4 as i32,
        8 as i32,
        15 as i32,
        16 as i32,
        23 as i32,
        30 as i32,
        42 as i32,
        50 as i32,
        89 as i32,
        99 as i32,
    ];
    let mut num_entries: u32 = (::core::mem::size_of::<[i32; 13]>()
        as u64)
        .wrapping_div(::core::mem::size_of::<i32>() as u64)
        as u32;
    let mut i: u32 = 0;
    list = 0 as *mut SListEntry;
    i = 0 as i32 as u32;
    while i < num_entries {
        slist_prepend(
            &mut list,
            &mut *entries.as_mut_ptr().offset(i as isize) as *mut i32
                as SListValue,
        );
        i = i.wrapping_add(1);
        i;
    }
    slist_sort(
        &mut list,
        Some(
            int_compare
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> i32,
        ),
    );
    assert!(slist_length(list) == num_entries);
    i = 0 as i32 as u32;
    while i < num_entries {
        let mut value: *mut i32 = 0 as *mut i32;
        value = slist_nth_data(list, i) as *mut i32;
        assert!(*value == sorted[i as usize]);
        i = i.wrapping_add(1);
        i;
    }
    slist_free(list);
    list = 0 as *mut SListEntry;
    slist_sort(
        &mut list,
        Some(
            int_compare
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> i32,
        ),
    );
    assert!(list.is_null());
}
#[no_mangle]
pub unsafe extern "C" fn test_slist_find_data() {
    let mut entries: [i32; 10] = [
        89 as i32,
        23 as i32,
        42 as i32,
        16 as i32,
        15 as i32,
        4 as i32,
        8 as i32,
        99 as i32,
        50 as i32,
        30 as i32,
    ];
    let mut num_entries: i32 = (::core::mem::size_of::<[i32; 10]>()
        as u64)
        .wrapping_div(::core::mem::size_of::<i32>() as u64)
        as i32;
    let mut list: *mut SListEntry = 0 as *mut SListEntry;
    let mut result: *mut SListEntry = 0 as *mut SListEntry;
    let mut i: i32 = 0;
    let mut val: i32 = 0;
    let mut data: *mut i32 = 0 as *mut i32;
    list = 0 as *mut SListEntry;
    i = 0 as i32;
    while i < num_entries {
        slist_append(
            &mut list,
            &mut *entries.as_mut_ptr().offset(i as isize) as *mut i32
                as SListValue,
        );
        i += 1;
        i;
    }
    i = 0 as i32;
    while i < num_entries {
        val = entries[i as usize];
        result = slist_find_data(
            list,
            Some(
                int_equal
                    as unsafe extern "C" fn(
                        *mut libc::c_void,
                        *mut libc::c_void,
                    ) -> i32,
            ),
            &mut val as *mut i32 as SListValue,
        );
        assert!(!result.is_null());
        data = slist_data(result) as *mut i32;
        assert!(*data == val);
        i += 1;
        i;
    }
    val = 0 as i32;
    assert!((slist_find_data(
        list,
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> i32,
        ),
        &mut val as *mut i32 as SListValue,
    ))
        .is_null());
    val = 56 as i32;
    assert!((slist_find_data(
        list,
        Some(
            int_equal
                as unsafe extern "C" fn(
                    *mut libc::c_void,
                    *mut libc::c_void,
                ) -> i32,
        ),
        &mut val as *mut i32 as SListValue,
    ))
        .is_null());
    slist_free(list);
}
#[no_mangle]
pub unsafe extern "C" fn test_slist_to_array() {
    let mut list: *mut SListEntry = 0 as *mut SListEntry;
    let mut array: *mut *mut libc::c_void = 0 as *mut *mut libc::c_void;
    list = generate_list_test_slist();
    array = slist_to_array(list);
    assert!(*array.offset(0 as i32 as isize)
        == &mut variable1_test_slist as *mut i32 as *mut libc::c_void);
    assert!(*array.offset(1 as i32 as isize)
        == &mut variable2_test_slist as *mut i32 as *mut libc::c_void);
    assert!(*array.offset(2 as i32 as isize)
        == &mut variable3_test_slist as *mut i32 as *mut libc::c_void);
    assert!(*array.offset(3 as i32 as isize)
        == &mut variable4_test_slist as *mut i32 as *mut libc::c_void);
    alloc_test_free(array as *mut libc::c_void);
    alloc_test_set_limit(0 as i32);
    array = slist_to_array(list);
    assert!(array.is_null());
    slist_free(list);
}
#[no_mangle]
pub unsafe extern "C" fn test_slist_iterate() {
    let mut list: *mut SListEntry = 0 as *mut SListEntry;
    let mut iter: SListIterator = SListIterator {
        prev_next: 0 as *mut *mut SListEntry,
        current: 0 as *mut SListEntry,
    };
    let mut data: *mut i32 = 0 as *mut i32;
    let mut a: i32 = 0;
    let mut i: i32 = 0;
    let mut counter: i32 = 0;
    list = 0 as *mut SListEntry;
    i = 0 as i32;
    while i < 50 as i32 {
        slist_prepend(&mut list, &mut a as *mut i32 as SListValue);
        i += 1;
        i;
    }
    counter = 0 as i32;
    slist_iterate(&mut list, &mut iter);
    slist_iter_remove(&mut iter);
    while slist_iter_has_more(&mut iter) != 0 {
        data = slist_iter_next(&mut iter) as *mut i32;
        counter += 1;
        counter;
        if counter % 2 as i32 == 0 as i32 {
            slist_iter_remove(&mut iter);
            slist_iter_remove(&mut iter);
        }
    }
    assert!((slist_iter_next(&mut iter)).is_null());
    slist_iter_remove(&mut iter);
    assert!(counter == 50 as i32);
    assert!(slist_length(list) == 25 as i32 as u32);
    slist_free(list);
    list = 0 as *mut SListEntry;
    counter = 0 as i32;
    slist_iterate(&mut list, &mut iter);
    while slist_iter_has_more(&mut iter) != 0 {
        data = slist_iter_next(&mut iter) as *mut i32;
        counter += 1;
        counter;
        if counter % 2 as i32 == 0 as i32 {
            slist_iter_remove(&mut iter);
        }
    }
    assert!(counter == 0 as i32);
}
#[no_mangle]
pub unsafe extern "C" fn test_slist_iterate_bad_remove() {
    let mut list: *mut SListEntry = 0 as *mut SListEntry;
    let mut iter: SListIterator = SListIterator {
        prev_next: 0 as *mut *mut SListEntry,
        current: 0 as *mut SListEntry,
    };
    let mut values: [i32; 49] = [0; 49];
    let mut i: i32 = 0;
    let mut val: *mut i32 = 0 as *mut i32;
    list = 0 as *mut SListEntry;
    i = 0 as i32;
    while i < 49 as i32 {
        values[i as usize] = i;
        slist_prepend(
            &mut list,
            &mut *values.as_mut_ptr().offset(i as isize) as *mut i32
                as SListValue,
        );
        i += 1;
        i;
    }
    slist_iterate(&mut list, &mut iter);
    while slist_iter_has_more(&mut iter) != 0 {
        val = slist_iter_next(&mut iter) as *mut i32;
        if *val % 2 as i32 == 0 as i32 {
            assert!(slist_remove_data(
                &mut list,
                Some(
                    int_equal
                        as unsafe extern "C" fn(
                            *mut libc::c_void,
                            *mut libc::c_void,
                        ) -> i32,
                ),
                val as SListValue,
            ) != 0 as i32 as u32);
            slist_iter_remove(&mut iter);
        }
    }
    slist_free(list);
}
static mut tests_test_slist: [UnitTestFunction; 15] = unsafe {
    [
        Some(test_slist_append as unsafe extern "C" fn() -> ()),
        Some(test_slist_prepend as unsafe extern "C" fn() -> ()),
        Some(test_slist_free as unsafe extern "C" fn() -> ()),
        Some(test_slist_next as unsafe extern "C" fn() -> ()),
        Some(test_slist_nth_entry as unsafe extern "C" fn() -> ()),
        Some(test_slist_nth_data as unsafe extern "C" fn() -> ()),
        Some(test_slist_length as unsafe extern "C" fn() -> ()),
        Some(test_slist_remove_entry as unsafe extern "C" fn() -> ()),
        Some(test_slist_remove_data as unsafe extern "C" fn() -> ()),
        Some(test_slist_sort as unsafe extern "C" fn() -> ()),
        Some(test_slist_find_data as unsafe extern "C" fn() -> ()),
        Some(test_slist_to_array as unsafe extern "C" fn() -> ()),
        Some(test_slist_iterate as unsafe extern "C" fn() -> ()),
        Some(test_slist_iterate_bad_remove as unsafe extern "C" fn() -> ()),
        None,
    ]
};
unsafe fn main_0_test_slist(
    mut argc: i32,
    mut argv: *mut *mut i8,
) -> i32 {
    run_tests(tests_test_slist.as_mut_ptr());
    return 0 as i32;
}
pub fn main_test_slist() {
    let mut args: Vec::<*mut i8> = Vec::new();
    for arg in ::std::env::args() {
        args.push(
            (::std::ffi::CString::new(arg))
                .expect("Failed to convert argument into CString.")
                .into_raw(),
        );
    }
    args.push(::core::ptr::null_mut());
    unsafe {
        ::std::process::exit(
            main_0_test_slist(
                (args.len() - 1) as i32,
                args.as_mut_ptr() as *mut *mut i8,
            ) as i32,
        )
    }
}
